package Test;

public class Test4 {
    public static void main(String[] args) {
        int[] arr = {1, 20, 30, 50, 100};
        double d = fen(arr);
        System.out.println("去掉一个最高分和一个最低分后的平均值为：" + d);
    }

    public static double fen(int[] arr) {
        //对数组进行排序
        int min = arr[0];
        int max = arr[0];
        int mun = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        for (int i = 0; i < arr.length; i++) {
            mun += arr[i];
        }
        double avg = (double) (mun - min - max) / (arr.length - 2);
        return avg;
    }
}

